package com.jiubodou.myoauth2.oauth2class.jiubodou;

import com.jiubodou.myoauth2.domain.LQQS;
import com.jiubodou.myoauth2.oauth2class.my.MyUserDetails;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.HashSet;

/**
 * @ClassName JiuBoDouUserDetailServiceImpl
 * @Description
 * @Author huyingliang
 * @Date 2023/5/12 16:41
 */
public class JiuBoDouUserDetailServiceImpl implements UserDetailsService {

//    String username="username-jiubodou";/*正常来说这里应该是前端传过来的 我这里就简化了一下*/
//    String password="password-jiubodou";
//    String code="code-jiubodou";

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        /*基本上就是 用 mybatisPlus等框架，根据 username 查找到数据的操作*/
        LQQS lqqs = new LQQS("username-jiubodou", "$2a$10$.mAC6U90qNj/CmIsQ0KWr.Lt4tbkfdB0wB0w57y/Su..7yiBoFH1K", "北京市海淀区", "123456789", "xxx@qq.com");

        /*封装权限*/
        HashSet<SimpleGrantedAuthority> authorities = new HashSet<>();
        authorities.add(new SimpleGrantedAuthority("admin"));
        authorities.add(new SimpleGrantedAuthority("user"));

        /*返回值的封装*/
        return new MyUserDetails(lqqs,authorities);
    }
}
